home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 11347 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.6 KB  |  69 lines

  1. Path: nntp-server.caltech.edu!mika
  2. From: mika@ariadne.cs.caltech.edu (Mika Nystroem)
  3. Newsgroups: comp.lang.c
  4. Subject: longjmp/setjmp madness
  5. Date: 23 Mar 1996 11:01:15 GMT
  6. Organization: California Institute of Technology, Pasadena
  7. Distribution: world
  8. Message-ID: <4j0llr$rvl@gap.cco.caltech.edu>
  9. NNTP-Posting-Host: ariadne.cs.caltech.edu
  10.  
  11.  
  12.  
  13. Hi everyone,
  14.   I have been trying to write a nasty little program here, and had some
  15. problems. I have managed to distill my problem to the following 
  16. unpleasantness. 
  17.   The man pages are a little sketchy on how longjmp and setjmp are supposed
  18. to work, but I don't *think* I have violated the specification. If I have,
  19. please correct me on that point. (I know that what this program is doing
  20. is incredibly nasty, and at least in this case, could be done much
  21. nicer.. I just want to know if it is written according to specs.)
  22. This program compiles and executes without problems on
  23.    sparc/SunOS 4.1.4
  24.    AXP/DEC UNIX 3.2
  25.  
  26. And compiles and executes with a segfault upon leaving p1() on
  27.    i386/NetBSD 1.1A
  28.    i386/Linux  1.3.x
  29.    i386/NeXTstep
  30.    sparc/NetBSD 1.1B
  31.  
  32. Ho hum.
  33.    Mika
  34.    <mika@vlsi.cs.caltech.edu>
  35.  
  36. P.S. If you wish to respond to me, please Cc: me in email. Thanks!
  37.  
  38. --- nasty begins here ---
  39. /* ltest.c 
  40.    mika@vlsi 
  41.  */
  42.  
  43. #include <setjmp.h>
  44. #include <stdio.h>
  45.  
  46. jmp_buf e1,e2,e3,e4;
  47.  
  48. void p1()
  49. {
  50.   if(!setjmp(e2)) longjmp(e1,1);
  51.   printf("p1 returning now\n"); fflush(stdout);
  52.   return;
  53. }
  54.   
  55. void
  56. main() 
  57. {
  58.   if(!setjmp(e1)) {
  59.     printf("calling p1\n");
  60.     p1();
  61.     printf("returning from p1()\n");
  62.     exit(0);
  63.   }
  64.   printf("longjmping to p1/e2\n");
  65.   longjmp(e2,1);
  66. }
  67.  
  68.  
  69.